#!/usr/bin/python
import os, pygame
import predef
from predef import *

def get_alliance(color):
    if color == PLAYER1:
        return PLAYER3
    if color == PLAYER2:
        return PLAYER4
    if color == PLAYER3:
        return PLAYER1
    if color == PLAYER4:
        return PLAYER2
        
        
class ChessMan(pygame.sprite.Sprite):
    def __init__(self, owner, type):
        pygame.sprite.Sprite.__init__(self)
        self.owner = owner
        self.type = type           # normal, enchantment, ...
        self.kind = None           # summoner, forcefielder, ...
        self.leftcorpse = False
        self.movement = 0
        self.attacker = False
        self.nonentities = False   # illusionist ability
        self.overlapping = False
        self.selectable = False
        self.father = None         # chess that who created this chess
        self.children = []         # chesses that was created by this chess
        self.inhibited = True      # being inhibited (by field, enchantment, enchantment_ad)
        self.seal = False          # be sealed by soothsayer's super power
        self.upkeep = False        # summoner
        
    def isEnemy(self, owner):
        if self.owner != owner and \
                owner != get_alliance(self.owner):
            return True
        else:
            return False

    def isCreature(self):
        return not self.overlapping


class ChessNormal(ChessMan):
    def __init__(self, owner, kind):
        ChessMan.__init__(self, owner, TYPE_NORMAL)
        self.kind = kind

        self.leftcorpse = True
        self.attacker = True
        self.selectable = True

        if kind == predef.KIND_SUMMONER:
            self.movement = 4
        elif kind == predef.KIND_ILLUSIONIST:
            self.movement = 3
            self.attacker = False
            self.nonentities = True
            self.clone = None
        elif kind == predef.KIND_FORCEFIELDER:
            self.movement = 2
        elif kind == predef.KIND_SCEPTRE:
            self.movement = 1
            self.leftcorpse = False
        elif kind == predef.KIND_NECROMANCER:
            self.movement = 2
        elif kind == predef.KIND_SOOTHSAYER:
            self.movement = 3
        elif kind == predef.KIND_SORCERER:
            self.movement = 4
        else:
            pass

class ChessLiving(ChessNormal):
    def __init__(self, owner, kind):
        ChessNormal.__init__(self, owner, kind)

class ChessWalkingDead(ChessNormal):
    def __init__(self, owner, kind):
        ChessNormal.__init__(self, owner, kind)
        self.leftcorpse = False

class ChessSummons(ChessMan):
    def __init__(self, owner):
        ChessMan.__init__(self, owner, TYPE_SUMMONS)

        self.kind = KIND_SUMMONS
        self.attacker = True
        self.movement = 1
        self.selectable = True

class ChessClone(ChessMan):
    def __init__(self, owner):
        ChessMan.__init__(self, owner, TYPE_CLONE)

        self.kind = KIND_CLONE
        self.attacker = False
        self.nonentities = True
        self.movement = 3
        self.selectable = True

class ChessCropse(ChessMan):
    def __init__(self, kind):
        ChessMan.__init__(self, None, TYPE_CORPSE)
        self.kind = kind

        self.overlapping = True

class ChessField(ChessMan):
    def __init__(self, owner):
        ChessMan.__init__(self, owner, TYPE_FIELD)

        self.overlapping = True

class ChessEnchantment(ChessMan):
    def __init__(self, owner):
        ChessMan.__init__(self, owner, TYPE_ENCHANTMENT)

        self.overlapping = True

class ChessEnchantmentAd(ChessMan):
    def __init__(self, owner):
        ChessMan.__init__(self, owner, TYPE_ENCHANTMENT_AD)

        self.overlapping = True

if __name__ == "__main__":
    test1 = ChessNormal("G", predef.KIND_NECROMANCER)
    test2 = ChessSummons("B")
    test3 = ChessClone("W", test2)
    test4 = ChessCropse(predef.KIND_ILLUSIONIST)
    test5 = ChessField("O")
    test6 = ChessEnchantment("G")
    test7 = ChessEnchantmentAd("B")

